<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	View application
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">

	<script type="text/javascript">

$(document).ready( function() {
	// alert('ready.');
	setInterval( 'reloadMailTable()', 2000 );
} );

function reloadMailTable()
{	
	// $('#mailtable')[0].innerHTML = 'Loading...';
	var dt = new Date();
	$('#mailtable').load('<%= Mailer.Utilities.Configuration.RelativeRootURL %>applications/PartialMailListTable/<%= ViewData["ID"] %>?dummy='+escape(dt.toString()));
}

	</script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
	<div class="pagetitle">
		<h1>
			Application: <em><%= ViewData[ "name" ] %></em></h1>
	</div>
	<div class="pagecontent">
		<p>
			<%= Html.ActionLink( "Edit application properties", "Edit", new { id = ViewData["ID"] } ) %>
			|
			<%= Html.ActionLink( "Add/create recipient", "New", "Recipient", new { application = ViewData[ "ID" ] }, null ) %>
		</p>
		<p>
			PUBLIC ID:
			<%= ViewData[ "PublicId" ] %><br />
			SECRET:
			<%= ViewData[ "Secret" ] %>
		</p>
		<p>
			<b>Public links:</b><br />
			<%= Html.RouteLink("Subscribe to newsletters", "PublicApp", new { action = "subscribe", id = ViewData["ID"] })%><br />
			<%= Html.RouteLink("Unsubscribe from newsletters", "PublicApp", new { action = "unsubscribe", id = ViewData["ID"] })%>
		</p>
		<p>
			<b>Recipient lists:</b>
		</p>
		<table style="width: 100%;">
			<tr>
				<th>
					List
				</th>
				<th>
					ID
				</th>
				<th>
					Recipients
				</th>
				<th>
					Public links
				</th>
			</tr>
			<% foreach (var l in (ViewData["Lists"] as IList<Mailer.Model.Types.List>))
	  { %>
			<tr>
				<td>
					<%= Html.ActionLink( l.Name, "View", "List", new { Id = l.ID }, null ) %>
				</td>
				<td>
					#<%= l.ShortName %>
				</td>
				<td>
					<%= l.NumRecipients %>
				</td>
				<td>
					<%= Html.RouteLink( "Subscribe", "PublicList", new { action="subscribe", id=l.ID } ) %>
					<%= Html.RouteLink( "Unsubscribe", "PublicList", new { action="unsubscribe", id=l.ID } ) %>
				</td>
			</tr>
			<% } %>
		</table>
		<p>
			<%= Html.ActionLink( "Create list", "New", "List", new { application = ViewData[ "ID" ] }, null ) %>
		</p>
		<p>
			<b>Latest mails:</b>
		</p>
		<div id="mailtable">
			<% Html.RenderPartial("PartialMailListTable"); %>
		</div>
		<p>
			<%= Html.ActionLink( "Create mail", "New", "Mail", new { application = ViewData[ "ID" ] }, null ) %>
			|
			<%= Html.ActionLink( "All mails", "MailArchive", "Application", new { id = ViewData[ "ID" ] }, null ) %>
		</p>
	</div>
</asp:Content>
